﻿Imports System.Data.SqlClient

Public Class Mofawid
    Public Id As Integer
    Public Nom As String
    Public Prenom As String
    Public Ville As String
    Public Adress As String
    Public Email As String
    Public type As String
    Public Remarque As String

    'Les constructeur -------------------------

    Sub New(ByVal Id As Integer, ByVal Nom As String, ByVal Prenom As String, ByVal Ville As String, ByVal Adress As String, ByVal Email As String, ByVal type As String, ByVal Remarque As String)
        Me.Id = Id
        Me.Nom = Nom
        Me.Prenom = Prenom
        Me.Ville = Ville
        Me.Adress = Adress
        Me.Email = Email
        Me.type = type
        Me.Remarque = Remarque
    End Sub

    Sub New(ByVal enregistrement As ArrayList)
        Me.Id = enregistrement.Item(0)
        Me.Nom = enregistrement.Item(1)
        Me.Prenom = enregistrement.Item(2)
        Me.Ville = enregistrement.Item(3)
        Me.Email = enregistrement.Item(5)
        Me.Adress = enregistrement.Item(4)
        Me.type = enregistrement.Item(6)
        Me.Remarque = enregistrement.Item(7)
    End Sub

    Sub New()

    End Sub

    'les listes ---------------------------------

    Public List_avoca_enemi As ArrayList
    Public List_mokhabara As ArrayList
    Public list_phone As New ArrayList


    'les fonctions ---------------------------

    Public Sub remplir_List_avoca_enemi()
        Me.List_avoca_enemi.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Avocat_Adversaire   where id in (  select Id_Avocat_Adversaire from Mofawad_Avocat_Adversaire  where Id_Mofawad  =" & Me.Id & ")", Partager.con)
        Partager.Open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Avocat_enemie(Partager.dr("id"), Partager.dr("Num_Prof"), Partager.dr("Nom_F"), Partager.dr("Prenom_F"), Partager.dr("Nom"), Partager.dr("Prenom"), Partager.dr("Ville"), Partager.dr("Autorite"), Partager.dr("Adresse"), Partager.dr("Email"), Partager.dr("Remarque"))
            Me.List_avoca_enemi.Add(khab)
        End While
        Partager.Close()
    End Sub

    Public Sub suprimmer_avoca_enemi(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete from Mofawad_Avocat_Adversaire    where Id_Avocat_Adversaire =" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_avoca_enemi()


    End Sub

    Public Sub Ajouter_avoca_enemi(ByVal idd As Integer)

        Dim cmd As New SqlClient.SqlCommand("insert into Mofawad_Avocat_Adversaire values(" & idd & "," & Me.Id & ")", Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_avoca_enemi()


    End Sub



    Public Sub remplir_List_mokhabara()
        Me.List_mokhabara.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Avocat_Mokhabara  where id in (  select Id_Avocat_Mokhabara from Mofawad_Avocat_Mokhabara where Id_Mofawad  =" & Me.Id & ")", Partager.con)
        Partager.Open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Avocat_mokhabara(Partager.dr("id"), Partager.dr("Num_Prof"), Partager.dr("Nom_F"), Partager.dr("Prenom_F"), Partager.dr("Nom"), Partager.dr("Prenom"), Partager.dr("Ville"), Partager.dr("Autorite"), Partager.dr("Email"), Partager.dr("Adresse"), Partager.dr("Remarque"))
            Me.List_mokhabara.Add(khab)
        End While
        Partager.Close()
    End Sub

    Public Sub suprimmer_mokhabara(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete from Mofawad_Avocat_Mokhabara    where Id_Avocat_Mokhabara =" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_mokhabara()


    End Sub

    Public Sub Ajouter_mokhabara(ByVal idd As Integer)

        Dim cmd As New SqlClient.SqlCommand("insert into Mofawad_Avocat_Mokhabara values(" & idd & "," & Me.Id & ")", Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_mokhabara()


    End Sub





    Public Sub remplir_List_list_phone()
        Partager.close()
        Me.list_phone.Clear()
        Partager.ad = New SqlDataAdapter("select id,Num,Type from phone where Id_Mofawad =" & Me.Id, Partager.conPhone)
        Partager.ds = New DataSet
        Partager.ad.Fill(Partager.ds, "phone")
        For Each f As DataRow In Partager.ds.Tables(0).Rows
            If f("Num") Is DBNull.Value Then
                f("Num") = ""
            End If
            Dim khab As New Phone(f("id"), f("Num"), f("Type"))
            Me.list_phone.Add(khab)

        Next
        Partager.Close()
    End Sub

    Public Sub suprimmer_phone(ByVal id As Integer, ByVal type As String)

        Dim cmd As New SqlClient.SqlCommand("delete from phone where Type ='" & type & "' and Id_Mofawad=" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        ' Me.remplir_List_list_phone()


    End Sub

    Public Sub Ajouter_phone(ByVal ph As Phone)

        Dim cmd As New SqlClient.SqlCommand("insert into phone(Num,Type,Id_Mofawad) values (@Num,@Type,@Id_Mofawad)", Partager.con)

        cmd.Parameters.Add("@Id_Mofawad", SqlDbType.VarChar).Value = Me.Id
        cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = ph.Type
        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num


        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        'Me.remplir_List_list_phone()


    End Sub

    Public Sub modifier_List_phone(ByVal idd As Integer, ByVal ph As Phone)



        Dim cmd As New SqlClient.SqlCommand("update phone set  Num=@Num where id" & Id, Partager.con)


        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_list_phone()

    End Sub

End Class
